{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DAY3 列表、循环和判断语句\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 列表的基础操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一个技术是: Python\n",
      "当前列表长度: 3\n",
      "最终列表内容: ['Python', 'Ruby', 'JavaScript']\n"
     ]
    }
   ],
   "source": [
    "# 1. 创建包含三个字符串的列表\n",
    "tech_list = [\"Python\", \"Java\", \"Go\"]\n",
    "\n",
    "# 2. 获取第一个元素\n",
    "first_tech = tech_list[0]\n",
    "\n",
    "# 3. 向列表末尾添加新元素\n",
    "tech_list.append(\"JavaScript\")\n",
    "\n",
    "# 4. 修改第二个元素\n",
    "tech_list[1] = \"Ruby\"\n",
    "\n",
    "# 5. 移除元素\"Go\"\n",
    "tech_list.remove(\"Go\")\n",
    "\n",
    "# 6. 计算列表当前长度\n",
    "current_length = len(tech_list)\n",
    "\n",
    "# 7. 使用f-string打印结果\n",
    "print(f\"第一个技术是: {first_tech}\")\n",
    "print(f\"当前列表长度: {current_length}\")\n",
    "print(f\"最终列表内容: {tech_list}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 循环语句"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "讲解一下debugger的操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1到100的和是: 5050\n"
     ]
    }
   ],
   "source": [
    "# 初始化总和变量\n",
    "total = 0\n",
    "\n",
    "# 使用for循环累加1到100\n",
    "for num in range(1, 101):  # range(1,101)表示从1到100（包含100）\n",
    "    total += num\n",
    "    # total = total + num\n",
    "# 打印结果\n",
    "print(f\"1到100的和是: {total}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`range()` 是 Python 内置函数，用于生成一个整数序列，常用于 for 循环中控制循环次数。\n",
    "\n",
    "**基本语法**：\n",
    "```\n",
    "range(stop)              # 从 0 开始到 stop-1\n",
    "range(start, stop)       # 从 start 开始到 stop-1\n",
    "range(start, stop, step) # 从 start 开始，步长为 step，到 stop-1\n",
    "```\n",
    "\n",
    "**参数说明**：\n",
    "- `start`: 起始数字（包含），默认为 0\n",
    "- `stop`: 结束数字（不包含，这很重要！）\n",
    "- `step`: 步长，默认为 1，可以是负数\n",
    "\n",
    "**常见用法示例**：\n",
    "\n",
    "| 代码 | 生成序列 | 说明 |\n",
    "|------|---------|------|\n",
    "| `range(5)` | 0, 1, 2, 3, 4 | 从 0 到 4 |\n",
    "| `range(1, 5)` | 1, 2, 3, 4 | 从 1 到 4 |\n",
    "| `range(1, 101)` | 1, 2, ..., 100 | 从 1 到 100 ✓ 本题使用 |\n",
    "| `range(0, 10, 2)` | 0, 2, 4, 6, 8 | 每次增加 2 |\n",
    "| `range(10, 0, -1)` | 10, 9, 8, ..., 1 | 倒序递减 |\n",
    "\n",
    "range()用来生成数字序列，for可以取出来这个序列。我们把这种可以被for循环取出来的叫做可迭代对象。\n",
    "\n",
    "实际上列表和字符串也是可迭代序列\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P\n",
      "y\n",
      "t\n",
      "h\n",
      "o\n",
      "n\n"
     ]
    }
   ],
   "source": [
    "for char in \"Python\":  # 逐个取出每个字符\n",
    "    print(char)  # P, y, t, h, o, n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python\n",
      "Ruby\n",
      "JavaScript\n"
     ]
    }
   ],
   "source": [
    "for tech in tech_list:  # 逐个取出每个元素\n",
    "    print(tech)  # 打印每个技术名称"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 判断语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "不优秀\n"
     ]
    }
   ],
   "source": [
    "score = 85\n",
    "\n",
    "if score >= 90:\n",
    "    print(\"优秀\")\n",
    "else:\n",
    "    print(\"不优秀\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "绿色提示：适宜温度\n"
     ]
    }
   ],
   "source": [
    "temperature = 25  # 可以修改这个值测试不同情况\n",
    "\n",
    "if temperature > 35:\n",
    "    print(\"红色预警：高温天气！\")\n",
    "elif temperature >= 28:\n",
    "    print(\"黄色预警：天气炎热\")\n",
    "elif temperature >= 20:\n",
    "    print(\"绿色提示：适宜温度\")\n",
    "else:\n",
    "    print(\"蓝色预警：注意保暖\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "题目答案"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "优秀分数个数: 2\n",
      "分数总和: 503\n",
      "平均分数: 83.833\n"
     ]
    }
   ],
   "source": [
    "# 1. 定义分数列表\n",
    "scores = [85, 92, 78, 65, 95, 88]\n",
    "\n",
    "# 2. 初始化变量\n",
    "excellent_count = 0\n",
    "total_score = 0\n",
    "\n",
    "# 3. 遍历列表并计算\n",
    "for score in scores:\n",
    "    total_score += score  # 4a. 累加总分\n",
    "    if score >= 90:      # 4b. 统计优秀分数\n",
    "        excellent_count += 1\n",
    "\n",
    "# 5. 计算平均分\n",
    "average_score = total_score / len(scores)\n",
    "\n",
    "# 6. 打印结果\n",
    "print(f\"优秀分数个数: {excellent_count}\")\n",
    "print(f\"分数总和: {total_score}\")\n",
    "print(f\"平均分数: {average_score:.3f}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "vs",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
